package be.kuleuven.cs.mop.domain.model.impl;

import be.kuleuven.cs.mop.domain.exceptions.TaskManagerException;


public class Field{
	
	private FieldType type;
	private Object value;
	
	public Field(FieldType type, Object value) throws TaskManagerException{
		setType(type);
		setValue(value);
	}
	
	public Field(FieldType type) throws TaskManagerException {
		setType(type);
		
	}
	
	public FieldType getType() {
		return type;
	}

	private void setType(FieldType type) throws TaskManagerException{
		if(type==null){
			throw new TaskManagerException(TaskManagerException.FIELD_TYPE_CAN_NOT_BE_NULL);
		}
		this.type = type;
	}

	public Object getValue() {
		return value;
	}

	private void setValue(Object value) throws TaskManagerException{
		if(value == null){
			throw new TaskManagerException(TaskManagerException.FIELD_VALUE_CAN_NOT_BE_NULL);
		}		
		if(value.getClass() == getType().getRepresentationClass()){
			this.value = value;
		}
		else{
			throw new TaskManagerException(TaskManagerException.INVALID_FIELD_VALUE_TYPE);
		}
		
	}
	
}